// Emboard header file
// control the behavior and get the status of the board

#ifndef ETB_EMBOARD_H_
#define ETB_EMBOARD_H_

#include "EventBus.h"
#include "SkyeyeImpl.h"

namespace etb {

  // Emboard
  // Main class of controlling the simulated board
  class Emboard : public EventClient, public SkyeyeCallback
  {

  // constructors and destructors
  public:
    Emboard(EventBus* bus);
    ~Emboard();

  // public members
  public:
    static const U8 DOWNLOAD_TO_NOR    = 0;
    static const U8 DOWNLOAD_TO_SDRAM  = 1;
    static const U8 DOWNLOAD_TO_NAND   = 2;

    static const U8 MACHINE_RUN      = 0;
    static const U8 MACHINE_STOP     = 1;
    static const U8 MACHINE_STEP     = 2;

  // public api
  public:
    void init(bool bootMode);

    // APIs for FakeJtag 
    void jtagGetCpuState(std::vector<U32>& regs);
    bool jtagStepRunMachine();
    void jtagStopMachine();
    void jtagPauseMachine();
    void jtagContinueMachine();
    void jtagSetPc(U32 addr);
    void jtagResetMachine();
    U8 jtagGetMachineState() { return state_; }
    U32 jtagGetInstruction();
    U32 jtagDownloadBinary(U8 target, U8 *binPtr, U32 addrOffset, U32 size);

  // inherited api
  public:
    void handleEvent(const std::string event);
    // Callback from SkyeyeyImpl
    void handleCallback(const std::string type, const std::string event);

  // private methods
  private:
    void runSim();
    void stopSim();
    void pauseSim();
    void stepSim();
    void keyPressed(int keyNum);
    void keyReleased(int keyNum);
    void setMachineState(U8 state);

    void checkToCreateNorFlash();
    void checkToCreateNandFlash();

  // private members
  private:
    EventBus*   bus_;
    U8          state_;
    // true for NOR flash, false for NAND
    bool        bootMode_;
  };

}

#endif  // ETB_EMBOARD_H_
